clear all
use "Directed Dyad example file.dta", replace


* Create directed dyad contagion spatial lag variable with (undirected) contiguity variable of form ik*jm as connectivity variable
* Note: ik*jm means that for other dyads to matter, both countries k and m must be contiguous to both i and j (complementary contiguity)
* The created spatial effect variable has no values for country_i=="Japan" since Japan has no contiguous neighbor in this dataset
spdir  patentsfiled, weight(contig_or_less1000km) source(country_i) target(country_j) time(year) link(ik*jm) sename(SL_dir_W_contig_compl) filename(SL_dir_W_contig_compl)

* As above, but (undirected) contiguity variable of form ik+jm as connectivity variable (substitutable contiguity)
* Note: ik+jm means that for other dyads to matter, it is sufficient if either country k or m is contiguous to i or j
spdir  patentsfiled, weight(contig_or_less1000km) source(country_i) target(country_j) time(year) link(ik+jm) sename(SL_dir_W_contig_subst) filename(SL_dir_W_contig_subst)


* As above, but excluding dyads that contain either i or j from exerting a spatial effect
spdir  patentsfiled, weight(contig_or_less1000km) source(country_i) target(country_j) time(year) link(ik+jm) exclusive sename(SL_direxcl_W_contig_subst) filename(SL_direxcl_W_contig_subst)

* Create directed dyad contagion spatial lag variable with directed exports from i to k as connectivity variable (exports from i to j are automatically transformed)
spdir  patentsfiled, weight(exports_i_to_j) source(country_i) target(country_j) time(year) link(ik) sename(SL_dir_W_exports_i_to_k) filename(SL_dir_W_exports_i_to_k)


* Create directed dyad contagion spatial lag variable with directed exports from k to i as connectivity variable (exports from i to j are automatically transformed)
spdir  patentsfiled, weight(exports_i_to_j) source(country_i) target(country_j) time(year) link(ki) sename(SL_dir_W_exports_k_to_i) filename(SL_dir_W_exports_k_to_i) 


